//
//  SportsHelpViewController.swift
//  funcode
//
//  Created by Wan Jiading on 2016/11/10.
//  Copyright © 2016年 WanJiading. All rights reserved.
//

import UIKit
import MJExtension

class SportsHelpViewController: UIViewController, UIAlertViewDelegate {

	@IBOutlet weak var ageTextField: UITextField!
	@IBOutlet weak var okBtn: UIButton!
	@IBOutlet weak var heartRateLabel: UILabel!
	
	
	
    override func viewDidLoad() {
        super.viewDidLoad()

		setupSubViews()
    }
    
    func tapViewGR(_ sender: UITapGestureRecognizer) {
        DebugLog(sender.view)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
	
	func setupSubViews() {
		okBtn.layer.cornerRadius = 5
		okBtn.layer.borderWidth = 0.5
		okBtn.layer.borderColor = UIColor.purple.cgColor
	}
	
	override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
		self.ageTextField.resignFirstResponder()
	}
	
	@IBAction func okBtnClick() {
		
//		（220─现在年龄）×0.8=最大运动心率
//		
//		（220─现在年龄）×0.6=最小运动心率
		
		if ageTextField.text?.count == 0 {
			return
		}
		
		let delta = 220 - Float(ageTextField.text!)!
		heartRateLabel.text = "最大心率:\(delta * 0.8)，最小心率:\(delta * 0.6)"
		
	}

    @IBAction func obj2JSON(_ sender: UIButton) {

        let userM = UserModel()
        userM.name = "阿里巴巴"
        userM.age = "15"
        let dogM = DogModel()
        dogM.age = "6"
//        dogM.name = ""
        userM.dog = dogM


        let str = userM.mj_JSONString()
        DebugLog(str)


    }

    @IBAction func showPayView() { // 未登录状态下开通会员有以下限制：\n1.仅为当前设备开通会员\n2.无法转移到其他设备\n3.卸载后无法找回
        showPayView("购买金卡会员", "登录后购买可跨平台享受会员权益", "登录购买", "为此设备购买")
    }

    func showPayView(_ title: String, _ message: String, _ firstButtonTitle: String, _ moreTitles: String) {
        let alertView =  UIAlertView(title: title, message: message, delegate: self, cancelButtonTitle: "取消", otherButtonTitles: firstButtonTitle, moreTitles)
        alertView.delegate = self
        alertView.show()
    }

    func alertView(_ alertView: UIAlertView, clickedButtonAt buttonIndex: Int) {
        if buttonIndex == 1 {
        } else if buttonIndex == 2 {
        }
    }
}
